package com.lagou.config;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Data
@Slf4j
@Configuration
@ConfigurationProperties(prefix = "mail")
public class EmailConfig {

    private String host;
    private String username;
    private String password;
    private String defaultEncoding;

    @Bean
    public JavaMailSender getJavaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost(host);
        mailSender.setUsername(username);
        mailSender.setPassword(password);
        mailSender.setDefaultEncoding(defaultEncoding);
        log.info("init mail sender, host={}, username={}, password={}, defaultEncoding={}",
                host, username, password, defaultEncoding);
        return mailSender;
    }

}
